using System;
using System.Reflection.Emit;
using Pine.Core;
using Pine.SourceParser.Tree;

namespace Pine.CodeGen
{
	public static class FieldReferenceCodeGenerator
	{		
		public static void GenerateBytecode(Context ctx, Expression expr, LocalBuilder lb) {
			FieldReference fr = (FieldReference) expr;
			LocalBuilder left = ctx.il.DeclareLocal(typeof(Value));
			fr.left.GenerateBytecode(ctx, left);
			ctx.il.Emit(OpCodes.Ldloc, left);
			ctx.il.Emit(OpCodes.Ldstr, fr.right);
			ctx.il.Emit(OpCodes.Callvirt, typeof(Value).GetMethod("FieldGet"));
			ctx.il.Emit(OpCodes.Stloc, lb);
		}
	}
}

